package com.lo23.data.utils;

import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class FormatConvert {

	public static XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) {
		try {
			GregorianCalendar gregorian = new GregorianCalendar();
			gregorian.setTime(date);
			XMLGregorianCalendar xmlGregorian = DatatypeFactory.newInstance()
					.newXMLGregorianCalendar(gregorian);

			return xmlGregorian;
		} catch (Exception e) {
			System.err.println(e);
			return null;
		}
	}

	public static Date xMLGregorianCalendarToDate(
			XMLGregorianCalendar gregCalendar) {
		try {
			return gregCalendar.toGregorianCalendar().getTime();
		} catch (Exception e) {
			System.err.println(e);
			return null;
		}
	}

}
